const app = getApp();
import ComFunJS from '@/common/comfun/ComFun'
const request = (url, options) => {
    return new Promise((resolve, reject) => {
        uni.request({
            url: `https://hd.kotom.cn${url}`,
            method: options.method,
            data: options.method === 'GET' ? options.data : options.data,
            header: {
                'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
                sessionId:ComFunJS.token
            },

            success(request) {
                if (request.data.code === 0) {
                    resolve(request.data);
                } else {
                    reject(request.data);
                }
            },

            fail(error) {
                reject(error.data);
            }
        });
    });
};

const get = (url, options = {}) => {
    return request(url, {
        method: 'GET',
        data: options
    });
};

const post = (url, options) => {
    return request(url, {
        method: 'POST',
        data: options
    });
};

const put = (url, options) => {
    return request(url, {
        method: 'PUT',
        data: options
    });
}; // 不能声明DELETE（关键字）

const remove = (url, options) => {
    return request(url, {
        method: 'DELETE',
        data: options
    });
};

module.exports = {
    get,
    post,
    put,
    remove
};
